home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
399_01
/
mined2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
58KB
|
2,339 lines
/* ================================================================== *
* Editor mined *
* Part 2 *
* ================================================================== */
#include "mined.h"
/* ================================================================== *
* Definitions specific for mined2.c *
* ================================================================== */
#ifndef copycommand
# ifdef vms
# define copycommand "copy %s %s"
# endif
# ifdef msdos
# define copycommand "copy %s %s > nul:"
# endif
#endif
/*
* viewonlyerr () outputs an error message with a beep
*/
void
viewonlyerr ()
{
ring_bell ();
error ("View only mode", NIL_PTR);
}
FLAG yank_status = NOT_VALID; /* Status of yank_file */
/* ================================================================== *
* Forward declarations *
* ================================================================== */
FLAG delete_text ();
void file_insert ();
void search ();
void re_search ();
void prev_search ();
void search_for ();
void yank ();
FLAG compile ();
int reverse_scroll ();
int find_y ();
int forward_scroll ();
int insert ();
int legal ();
int line_check ();
int check_string ();
int in_list ();
int star ();
FLAG checkmark ();
/* ================================================================== *
* Move Commands *
* ================================================================== */
/*
* Move one line up.
*/
void
MUP ()
{
if (hop_flag > 0) HIGH ();
else if (y == 0) { /* Top line of screen. Scroll one line */
if (reverse_scroll (TRUE) != ERRORS) {
move_y (y);
}
}
else /* Move to previous line */
move_y (y - 1);
}
/*
* Move one line down.
*/
void
MDN ()
{
if (hop_flag > 0) LOW ();
else if (y == last_y) { /* Last line of screen. Scroll one line */
if (bot_line->next == tail && bot_line->text [0] != '\n') {
/* dummy_line (); don't create new empty line ! */
/* MDN (); */
return;
}
else {
(void) forward_scroll (TRUE);
move_y (y);
}
}
else /* Move to next line */
move_y (y + 1);
}
/*
* Move left one position.
*/
void
MLF ()
{
if (hop_flag > 0) BLINE ();
else if (x == 0 && get_shift (cur_line->shift_count) == 0) {/* Begin of line */
if (cur_line->prev != header) {
MUP (); /* Move one line up */
move_to (LINE_END, y);
}
}
else
move_to (x - 1, y);
}
/*
* Move right one position.
*/
void
MRT ()
{
if (hop_flag > 0) ELINE ();
else if (* cur_text == '\n') {
if (cur_line->next != tail) { /* Last char of file */
MDN (); /* Move one line down */
move_to (LINE_START, y);
}
}
else
move_to (x + 1, y);
}
/*
* Move to top of screen
*/
void
HIGH ()
{
move_y (0);
}
/*
* Move to bottom of screen
*/
void
LOW ()
{
move_y (last_y);
}
/*
* Move to begin of line.
*/
void
BLINE ()
{
move_to (LINE_START, y);
}
/*
* Move to end of line.
*/
void
ELINE ()
{
move_to (LINE_END, y);
}
/*
* GOTO () prompts for a linenumber and moves to that line.
*/
void
goline (number)
int number;
{
LINE * line;
if (number <= 0 || (line = proceed (header->next, number - 1)) == tail)
error ("Illegal line number: ", num_out ((long) number));
else {
clear_status ();
move_y (find_y (line));
}
}
void
goproz (number)
int number;
{
goline (number * total_lines / 100);
}
void
GOTO ()
{
uchar c;
char end;
int number;
if (! char_ready_within (500)) status_msg ("HOP ... command (fortified) or line number...");
if (quit == TRUE) return;
c = readchar ();
if (quit == TRUE) return;
if ('0' <= c && c <= '9') {
end = get_number ("Please continue line number...", c, & number);
if (end == '%')
goproz (number);
else if (end != ERRORS)
goline (number);
return;
}
else {
clear_status ();
hop_flag = 1;
(* key_map [c]) (c);
return;
}
}
/*
* Scroll forward one page or to eof, whatever comes first. (Bot_line becomes
* top_line of display.) Try to leave the cursor on the same line. If this is
* not possible, leave cursor on the line halfway the page.
*/
void
PD ()
{
register int i;
int new_y;
if (hop_flag > 0) {hop_flag = 0; EFILE (); return;}
for (i = 0; i < SCREENMAX; i ++)
if (forward_scroll (page_scroll) == ERRORS)
break; /* EOF reached */
if (y - i < 0) /* Line no longer on screen */
new_y = (page_stay == TRUE) ? 0 : SCREENMAX >> 1;
else new_y = y - i;
if (page_scroll == FALSE) display (0, top_line, last_y, new_y);
move_y (new_y);
}
/*
* Scroll backwards one page or to top of file, whatever comes first.
* (Top_line becomes bot_line of display).
* The very bottom line (YMAX) is always blank.
* Try to leave the cursor on the same line.
* If this is not possible, leave cursor on the line halfway the page.
*/
void
PU ()
{
register int i;
int new_y;
if (hop_flag > 0) {hop_flag = 0; BFILE (); return;}
for (i = 0; i < SCREENMAX; i ++) {
if (reverse_scroll (page_scroll) == ERRORS)
/* should also flag reverse_scroll that clearing of
bottom line is not desired */
break; /* Top of file reached */
}
if (y + i > SCREENMAX) /* line no longer on screen */
new_y = (page_stay == TRUE) ? last_y : SCREENMAX >> 1;
else
new_y = y + i;
if (can_scroll_reverse == TRUE && page_scroll == TRUE) {
set_cursor (0, YMAX); /* Erase very bottom line */
clear_lastline ();
}
else display (0, top_line, last_y, new_y);
move_y (new_y);
}
/*
* Go to top of file, scrolling if possible, else redrawing screen.
*/
void
BFILE ()
{
if (proceed (top_line, - SCREENMAX) == header)
PU (); /* It fits. Let PU do it */
else {
reset (header->next, 0);/* Reset top_line, etc. */
RD_y (0); /* Display full page */
}
move_to (LINE_START, 0);
}
/*
* Go to last position of text, scrolling if possible, else redrawing screen
*/
void
EFILE ()
{
/* if (tail->prev->text [0] != '\n') dummy_line (); */
if (proceed (bot_line, SCREENMAX) == tail)
PD (); /* It fits. Let PD do it */
else {
reset (proceed (tail->prev, - SCREENMAX), SCREENMAX);
RD_y (last_y); /* Display full page */
}
move_to (LINE_END /* not START ("EFILE"!) */, last_y);
}
/*
* Scroll one line up. Leave the cursor on the same line (if possible).
*/
void
SU ()
{
register int i;
if (hop_flag > 0) {
hop_flag = 0;
for (i = 0; i < (SCREENMAX >> 1); i ++) SU ();
return;
}
if (reverse_scroll (TRUE) != ERRORS) { /* else we are at top of file */
move_y ((y == SCREENMAX) ? SCREENMAX : y + 1);
}
}
/*
* Scroll one line down. Leave the cursor on the same line (if possible).
*/
void
SD ()
{
register int i;
if (hop_flag > 0) {
hop_flag = 0;
for (i = 0; i < (SCREENMAX >> 1); i ++) SD ();
return;
}
if (forward_scroll (TRUE) != ERRORS)
move_y ((y == 0) ? 0 : y - 1);
}
/*
* Perform a forward scroll. It returns ERRORS if we're at the last line of
* the file.
*/
int
forward_scroll (update)
FLAG update;
{
if (bot_line->next == tail) /* Last line of file. No dice */
return ERRORS;
top_line = top_line->next;
bot_line = bot_line->next;
cur_line = cur_line->next;
/* Perform the scroll on screen */
if (update == TRUE) {
scroll_forward ();
set_cursor (0, SCREENMAX);
line_print (bot_line);
}
return FINE;
}
/*
* Perform a backwards scroll. It returns ERRORS if we're at the first line
* of the file. It updates the display completely if update is TRUE.
* Otherwise it leaves that to the caller (page up function).
*/
int
reverse_scroll (update)
FLAG update;
{
if (top_line->prev == header)
return ERRORS; /* Top of file. Can't scroll */
if (last_y != SCREENMAX) /* Reset last_y if necessary */
last_y ++;
else
bot_line = bot_line->prev; /* Else adjust bot_line */
top_line = top_line->prev;
cur_line = cur_line->prev;
/* Perform the scroll on screen */
if (update == TRUE)
if (can_scroll_reverse == TRUE) {
set_cursor (0, 0);
scroll_reverse ();
set_cursor (0, YMAX); /* Erase very bottom line */
clear_lastline ();
set_cursor (0, 0);
line_print (top_line);
}
else display (0, top_line, last_y, y);
return FINE;
}
/*----------------------*
* Word moves *
*----------------------*/
/*
* A word was previously defined as a number of non-blank charact